package cn.edu.lcu.cs.javaprogramming.collection;

import org.junit.jupiter.api.Test;

import java.util.ArrayList;

import static org.junit.jupiter.api.Assertions.*;

/**
 * ArrayList演示
 *
 * @author ling
 * @date 2022/3/19 14:00
 */
public class ArrayListDemo {

    @Test
    void testCapacity() {
        int initialCapacity = 50;
        ArrayList<String> list = new ArrayList<>(initialCapacity);
        // java.lang.IndexOutOfBoundsException: Index: 20, Size: 0
        assertThrows(IndexOutOfBoundsException.class, () -> list.add(2, "20"));
    }
}
